﻿using Base.Common.Events;
using Base.ModuleBase;
using Base.ModuleBase.Notifications;
using Prism.Commands;
using Prism.Common;
using Prism.Events;
using Prism.Interactivity.InteractionRequest;
using Prism.Ioc;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Input;

namespace Modules.ModuleA.ViewModels
{
    public class UserControl2ViewModel : ViewModelBase
    {
        #region 成员
        //private InteractionRequest<ViewNotification> _addServerDialog;
        ///// <summary>
        ///// 添加服务页面
        ///// </summary>
        //public InteractionRequest<ViewNotification> AddServerDialog
        //{
        //    get { return _addServerDialog; }
        //    set
        //    {
        //        _addServerDialog = value;
        //        NotifyChange(nameof(AddServerDialog));
        //    }
        //}
        #endregion

        #region 属性
        private string m_StringValue = string.Empty;
        /// <summary>
        /// 测试值
        /// </summary>
        public string StringValue
        {
            get
            {
                return m_StringValue;
            }
            set
            {
                SetProperty(ref m_StringValue, value);
            }
        }

        private string m_UserControlTitle = string.Empty;
        /// <summary>
        /// 测试值
        /// </summary>
        public string UserControlTitle
        {
            get
            {
                return m_UserControlTitle;
            }
            set
            {
                SetProperty(ref m_UserControlTitle, value);
            }
        }
        #endregion

        #region 构造
        public UserControl2ViewModel()
        {

        }
        #endregion

        #region 方法

        #region 重写
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="param"></param>
        public override void Init(object param)
        {

        }

        /// <summary>
        /// 绑定命令
        /// </summary>
        /// <param name="cmdCollection"></param>
        public override void BindCommands(CommandBindingCollection cmdCollection)
        {
            base.BindCommands(cmdCollection);
        }

        /// <summary>
        /// 绑定事件
        /// </summary>
        public override void BindEvents()
        {
            base.BindEvents();
            GlobalManager.EventAggregator.GetEvent<ModuleATestEvent>().Subscribe(OnModuleATestEvent);
        }

        /// <summary>
        /// 拖拽移动(不需要可以去除)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void PreviewDragOver(object sender, DragEventArgs e)
        {
            base.PreviewDragOver(sender, e);
        }

        /// <summary>
        /// 拖拽放下(不需要可以去除)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void Drop(object sender, DragEventArgs e)
        {
            base.Drop(sender, e);
        }

        /// <summary>
        /// 登出
        /// </summary>
        /// <param name="args"></param>
        public override void OnLogout(object args)
        {
            base.OnLogout(args);
        }

        #endregion

        #region 命令
        /// <summary>
        /// 测试弹窗按钮
        /// </summary>
        public DelegateCommand<object> TempMessageCommand
        {
            get
            {
                return new DelegateCommand<object>(p =>
                {
                    //GlobalManager.DialogService.ShowNotification("测试提示弹窗");
                    GlobalManager.DialogService.ShowView("CommonInfo", "");
                });
            }
        }
        /// <summary>
        /// 测试弹窗按钮
        /// </summary>
        public DelegateCommand<object> TempMessage2Command
        {
            get
            {
                return new DelegateCommand<object>(p =>
                {
                    GlobalManager.DialogService.ShowTip("测试Tip弹窗");
                });
            }
        }

        /// <summary>
        /// 测试弹窗按钮
        /// </summary>
        public DelegateCommand<object> TempMessage1Command
        {
            get
            {
                return new DelegateCommand<object>(p =>
                {
                    GlobalManager.DialogService.ShowConfirmation("测试确认弹窗", r =>
                    {
                        if (r.Result == ButtonResult.None)
                            StringValue = "Result is None";
                        else if (r.Result == ButtonResult.OK)
                            StringValue = "Result is OK";
                        else if (r.Result == ButtonResult.Cancel)
                            StringValue = "Result is Cancel";
                        else
                            StringValue = "I Don't know what you did!?";
                    });
                });
            }
        }
        #endregion


        /// <summary>
        /// 测试订阅消息
        /// </summary>
        /// <param name="obj"></param>
        private void OnModuleATestEvent(string obj)
        {
            UserControlTitle = "收到消息:" + obj;
        }
        #endregion
    }
}
